<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垃圾投放记录</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #e8f5fe; /* 背景颜色调整为浅蓝色 */
            margin: 0;
            padding: 0;
            color: #333;
        }
        .container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
        h1 {
            text-align: center;
            color: #f8f8f8;
            margin-bottom: 20px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            border-radius: 8px;
            overflow: hidden;
        }
        th, td {
            padding: 12px;
            text-align: center;
            border: 1px solid #ddd;
            transition: background-color 0.3s; /* 添加渐变效果 */
        }
        th {
            background-color: #007BFF;
            color: #fff;
            cursor: pointer;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #e0e0e0;
        }
        .header {
            background-color: #007BFF;
            color: #fff;
            padding: 10px 0;
            text-align: center;
            border-radius: 8px;
        }
        .loading {
            text-align: center;
            margin-top: 20px;
        }
        .loading img {
            width: 50px;
            height: 50px;
        }
        .icon {
            width: 20px;
            height: 20px;
            vertical-align: middle;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>总垃圾投放记录一览</h1>
    </div>
    <table id="wasteRecordsTable">
        <thead>
        <tr>
            <th>编号</th>
            <th>居民编号</th>
            <th>垃圾类型</th>
            <th>投放时间</th>
            <th>重量 (kg)</th>
            <th>投放地点</th>
            <th>审核状态</th>
        </tr>
        </thead>
        <tbody>
        <!-- 垃圾投放记录将在此处动态插入 -->
        </tbody>
    </table>
    <div class="loading" id="loading">
        <img src="loading.gif" alt="加载中">
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', fetchWasteRecords);

    function fetchWasteRecords() {
        const loading = document.getElementById('loading');
        loading.style.display = 'block'; // 显示加载动画
        fetch('/waste/selectWasteRecord')
            .then(response => response.json())
            .then(data => {
                const tableBody = document.querySelector('#wasteRecordsTable tbody');
                tableBody.innerHTML = ''; // 清除现有记录

                data.forEach(record => {
                    const row = document.createElement('tr');
                    row.innerHTML = `
                            <td>${record.id}</td>
                            <td>${record.residentId}</td>
                            <td>${record.type}</td>
                            <td>${record.time}</td>
                            <td>${record.weight}</td>
                            <td>${record.location}</td>
                            <td>${record.status}</td>
                        `;
                    tableBody.appendChild(row);
                });
                loading.style.display = 'none'; // 隐藏加载动画
            })
            .catch(error => {
                console.error('错误:', error);
                alert('加载数据时出错，请稍后再试！');
                loading.style.display = 'none'; // 隐藏加载动画
            });
    }
</script>
</body>
</html>